using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerMove : MonoBehaviour
{
    public static float MaxLeft, MaxRight;
    // Start is called before the first frame update
    void Start()
    {
        MaxLeft = -8.3f;
        MaxRight = 8.3f;
    }
    
    private void Move()
    {
        Debug.Log(MaxLeft + "  " + MaxRight);
        if (PlayerInfo.CanMove == false) return;
        float h = Input.GetAxisRaw("Horizontal");
        float v = Input.GetAxisRaw("Vertical");
        if(transform.position.x>=MaxLeft&&transform.position.x<=MaxRight)
            transform.position += Vector3.right*h*Time.deltaTime*5;

        if (transform.position.x < MaxLeft)
        {
            if (h == 1)
            {
                transform.position += Vector3.right * h * Time.deltaTime * 5;
            }
        }
        if (transform.position.x > MaxRight)
        {
            if (h == -1)
            {
                transform.position += Vector3.right * h * Time.deltaTime * 5;
            }
        }

        if (transform.position.y > -4 && transform.position.y < 4)
        {
            transform.position += Vector3.up*v*Time.deltaTime * 5;
        }
        if (transform.position.y <= -4)
        {
            if (v == 1)
            {
                transform.position += Vector3.up *v*Time.deltaTime * 5;
            }
        }
        if (transform.position.y >= 2)
        {
            if (v == -1)
            {
                transform.position += Vector3.up * v * Time.deltaTime * 5;
            }
        }
    }
    // Update is called once per frame
    void Update()
    {
        Move();
        
    }
}
